package com.yanqu.road.server.cmd.activity.xingyoushanshui;

import com.yanqu.road.entity.activity.youxing.config.XingYouConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.shanshui.XingYouShanShuiMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = XingYouShanShuiProto.ShanShuiTradeShipGiftReq.class, respMsg = XingYouShanShuiProto.ShanShuiTradeShipGiftRsp.class)
@Cmd(code = Protocol.S_XING_YOU_SHAN_SHUI_TRADE_SHIP_GIFT, desc = "贸易船领取赠礼（队友祈愿分享）")
public class ShanShuiTradeShipGiftCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        XingYouConfig config = XingYouShanShuiMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        XingYouShanShuiProto.ShanShuiTradeShipGiftReq req = XingYouShanShuiProto.ShanShuiTradeShipGiftReq.parseFrom(packet.getBytes());
        player.sendUnionActivityGroupPacket(Protocol.C_XING_YOU_SHAN_SHUI_TRADE_SHIP_GIFT, req.toBuilder(), config.getActivityInfo().getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_XING_YOU_SHAN_SHUI_TRADE_SHIP_GIFT, XingYouShanShuiProto.ShanShuiTradeShipGiftRsp.newBuilder().setRet(ret));
        }
    }
}
